<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>微电影管理系统</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/resource/static/base/images/logo.png">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/resource/static/admin/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resource/static/fonts/css/font-awesome.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resource/static/ionicons/css/ionicons.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resource/static/admin/dist/css/AdminLTE.min.css">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/resource/static/admin/dist/css/skins/_all-skins.min.css">
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/resource/static/admin/plugins/datepicker/datepicker3.css">
    <style>
        * {
            font-family: "Microsoft YaHei";
        }

        .table > tbody > tr > td, .table > tbody > tr > th, .table > tfoot > tr > td, .table > tfoot > tr > th, .table > thead > tr > td, .table > thead > tr > th {
            vertical-align: middle;
            text-align: center;
        }

    </style>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <%@ include file="../5-public/AdminSidebar.jsp" %>

    <div class="content-wrapper">
        <!--内容-->
        <section class="content-header">
            <h1>微电影管理系统</h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 收藏管理</a></li>
                <li class="active">收藏列表</li>
            </ol>
        </section>
        <section class="content" id="showcontent">
            <div class="row">
                <div class="col-md-12">
                    <div class="box box-primary">
                        <div class="box-header">
                            <h3 class="box-title">收藏列表</h3>
                            <div class="box-tools">
                                <div class="input-group input-group-sm" style="width: 150px;">
                                    <input id="inputText" type="text" name="table_search" class="form-control pull-right"
                                           placeholder="请输入关键字..." >

                                    <div class="input-group-btn">
                                        <button type="button" onclick="search()" class="btn btn-default"><i class="fa fa-search"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>



                        <div class="box-body table-responsive no-padding">
                            <table class="table table-hover">
                                <tbody>
                                <tr>
                                    <th>编号</th>
                                    <th>电影</th>
                                    <th>用户</th>
                                    <th>添加时间</th>
                                    <th>操作事项</th>
                                </tr>
                                <tr>
                                    <%--                                    <td>1</td>--%>
                                    <%--                                    <td>环太平洋</td>--%>
                                    <%--                                    <td>张小明</td>--%>
                                    <%--                                    <td>2017-06-01</td>--%>
                                    <c:forEach items="${pageInfo.list}" var="favortie">
                                <tr>
                                    <td>${favortie.favoriteVideosId}</td>
                                    <td>${favortie.videoName}</td>
                                    <td>${favortie.personName}</td>
                                    <td>${favortie.collectionTime}</td>
                                    <td>
                                        <a class="label label-danger" onclick="cut(this)">删除</a>

                                    </td>

                                </tr>
                                </c:forEach>

                                </tr>
                                </tbody>



                            </table>
                        </div>
                        <div class="box-footer clearfix">
                            <ul class="pagination" id="pagination">
                                <li><a href="<%=request.getContextPath()%>/admin/favoritePage?page=1&size=5" aria-label="Previous">首页</a></li>
                                <li><a
                                        href="<%=request.getContextPath()%>/admin/favoritePage?page=${pageInfo.pageNum-1}&size=5">上一页</a></li>
                                <c:forEach begin="1" end="${pageInfo.pages}"  var="pageNumber">
                                    <li>
                                        <a href="<%=request.getContextPath()%>/admin/favoritePage?page=${pageNumber}&size=5">${pageNumber}</a>
                                    </li>
                                </c:forEach>
                                <li><a href="<%=request.getContextPath()%>/admin/favoritePage?page=${pageInfo.pageNum+1}&size=5">下一页</a></li>
                                <li><a href="<%=request.getContextPath()%>/admin/favoritePage?page=${pageInfo.pages}&size=5" aria-label="Next">尾页</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <!--内容-->
    </div>
    <footer class="main-footer">
        <div class="pull-right hidden-xs">
            <b>版本</b> 1.0
        </div>
        <strong>版权 &copy; 2017-2018 归<a href="">xxx</a>.</strong> 所有
    </footer>
    <div class="control-sidebar-bg"></div>
</div>
<script src="${pageContext.request.contextPath}/resource/static/admin/plugins/jQuery/jQuery-2.2.0.min.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/plugins/fastclick/fastclick.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/dist/js/app.min.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/dist/js/demo.js"></script>
<script src="//cdn.bootcss.com/holder/2.9.4/holder.min.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"
        charset="UTF-8"></script>


</body>
</html>
<script>

    function search() {
        var input = $('#inputText').val();
        if (input==''){
        window.location="/admin/favoritePage"
        return
        }
        let fromData={
            "input":input
        }
        $.ajax({
            url: "/admin/favoriteSearch",
            data: fromData,
            type:"post",
            dataType: "json",
            success: function (res){



                $('tbody').empty()
                var data = res.data;
                $('tbody').append("<tr><th>编号</th><th>电影</th><th>用户</th><th>添加时间</th><th>操作事项</th></tr>")
                for (let i = 0; i <data.length; i++) {
                    $('tbody').append("<tr><th>"+data[i].favoriteVideosId+"</th><th>"+data[i].videoName+"</th><th>"+data[i].personName+"</th><th>"+data[i].collectionTime+"</th><td><a class='label label-danger 'onclick='cut(this)'>删除</a></td></tr>")


                }
                $('#pagination').empty()
            },
            error: function (){

            }
        })
    }



    function cut(obj) {
         let favoiteId = $(obj).parent().parent().children(":first").text();
        $.ajax({
            url: "/admin/move/DeleteById?favoiteId="+favoiteId,
            type:"get",
            dataType: "json",
            success: function (data){
               if (data.code==200){
                   alert("删除成功")
                   window.location.reload()
               }
            },
            error: function (e2){
                console.log(e2)

            }
        })
    }

</script>